package cn.ilikes.tools.nosql.jpa;

import org.slf4j.Logger;

import cn.ilikes.tools.logs.Loggerfactory;
import cn.ilikes.tools.nosql.jpa.classloads.JPASQLClassLoader;
import cn.ilikes.tools.nosql.jpa.classloads.porxys.CglibLazyInitializerFactory;
import cn.ilikes.tools.nosql.jpa.classloads.porxys.LazyInitializerFactory;

/**
 * JPA HBase 全局变量
 * 
 * @author fack
 * 
 */
public class JPASQLSystemEnv {

	private static Logger logger = Loggerfactory.instance(JPASQLSystemEnv.class);

	private boolean issysinit = false;

	private JPASQLClassLoader jPASQLSysClassLoader = new JPASQLClassLoader(Thread.currentThread().getContextClassLoader());

	private LazyInitializerFactory lazyInitializerFactory = new CglibLazyInitializerFactory();

	public void init() {
		Loggerfactory.info(logger, "JPA SQL System Env init success ! ");
		issysinit = true;

	}

	public boolean isIssysinit() {
		return issysinit;
	}

	public JPASQLClassLoader getjPASQLSysClassLoader() {
		checkInit();
		return jPASQLSysClassLoader;
	}

	public void setjPASQLSysClassLoader(JPASQLClassLoader jPASQLSysClassLoader) {
		this.jPASQLSysClassLoader = jPASQLSysClassLoader;
	}

	public LazyInitializerFactory getLazyInitializerFactory() {
		checkInit();
		return lazyInitializerFactory;
	}

	private void checkInit() {
		boolean init = isIssysinit();
		if (!init)
			throw new JPASQLRunTimeException("JPA SQL System Env NOT INIT ;Please first init ! ");
	}

}
